From 856641cce5114764cc41a25e57651e0f14a2778f Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 2 Dec 2016 11:25:55 +1300 Subject: [PATCH] Be a bit more careful not to crash if the compiler doesn't support --crate-type metadata --- src/cargo/ops/cargo_compile.rs | 2 +- src/cargo/ops/cargo_rustc/context.rs | 34 ++++++++++++++++++---------- src/cargo/util/toml.rs | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index da6f538ce..b44b3e025 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -65,7 +65,7 @@ pub struct CompileOptions<'a> { pub target_rustc_args: Option<&'a [String]>, } -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Debug)] pub enum CompileMode { Test, Build, diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index bb8176a6f..f01c0b141 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -174,13 +174,17 @@ impl<'a, 'cfg> Context<'a, 'cfg> { "RUSTFLAGS")?; let mut process = self.config.rustc()?.process(); process.arg("-") - .arg("--crate-name").arg("_") + .arg("--crate-name").arg("___") .arg("--print=file-names") .args(&rustflags) .env_remove("RUST_LOG"); for crate_type in crate_types { - process.arg("--crate-type").arg(crate_type); + // Here and below we'll skip the metadata crate-type because it is + // not supported by older compilers. We'll do this one manually. + if crate_type != "metadata" { + process.arg("--crate-type").arg(crate_type); + } } if kind == Kind::Target { process.arg("--target").arg(&self.target_triple()); @@ -204,31 +208,37 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let mut map = HashMap::new(); for crate_type in crate_types { let not_supported = error.lines().any(|line| { - line.contains("unsupported crate type") && - line.contains(crate_type) + (line.contains("unsupported crate type") || + line.contains("unknown crate type")) && + line.contains(crate_type) }); if not_supported { - if crate_type == "metadata" { - bail!("compiler does not support `--crate-type metadata`, \ - cannot run `cargo check`."); - } map.insert(crate_type.to_string(), None); - continue + continue; + } + if crate_type == "metadata" { + continue; } let line = match lines.next() { Some(line) => line, None => bail!("malformed output when learning about \ target-specific information from rustc"), }; - let mut parts = line.trim().split('_'); + let mut parts = line.trim().split("___"); let prefix = parts.next().unwrap(); let suffix = match parts.next() { Some(part) => part, None => bail!("output of --print=file-names has changed in \ the compiler, cannot parse"), }; - map.insert(crate_type.to_string(), - Some((prefix.to_string(), suffix.to_string()))); + + map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string()))); + } + + // Manually handle the metadata case. If it is not supported by the + // compiler we'll error out elsewhere. + if crate_types.contains("metadata") { + map.insert("metadata".to_string(), Some(("lib".to_owned(), ".rmeta".to_owned()))); } let cfg = if has_cfg { diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 7d47bcf92..e670715d4 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -1249,7 +1249,7 @@ fn build_profiles(profiles: &Option) -> Profiles { profiles.and_then(|p| p.doc.as_ref())), custom_build: Profile::default_custom_build(), check: merge(Profile::default_check(), - profiles.and_then(|p| p.dev.as_ref())), + profiles.and_then(|p| p.dev.as_ref())), }; // The test/bench targets cannot have panic=abort because they'll all get // compiled with --test which requires the unwind runtime currently -- 2.30.2